﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 
using System.Data.SqlClient;
using System.Data; 
using Stone.DataContracts;
using Stone.Library.DB;

namespace CourseArraging.DAO
{
    public class Zap2DAO
    { 
        public void Add(Zap2Entity model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into zap2(");
            strSql.Append("zap_sb_id,zap_sb_no,zap_sb_name,T11,T12,T13,T14,T15,T16,T21,T22,T23,T24,T25,T26,T31,T32,T33,T34,T35,T36,T41,T42,T43,T44,T45,T46,T51,T52,T53,T54,T55,T56,T61,T62,T63,T64,T65,T66,T71,T72,T73,T74,T75,T76)");
            strSql.Append(" values (");
            strSql.Append("@zap_sb_id,@zap_sb_no,@zap_sb_name,@T11,@T12,@T13,@T14,@T15,@T16,@T21,@T22,@T23,@T24,@T25,@T26,@T31,@T32,@T33,@T34,@T35,@T36,@T41,@T42,@T43,@T44,@T45,@T46,@T51,@T52,@T53,@T54,@T55,@T56,@T61,@T62,@T63,@T64,@T65,@T66,@T71,@T72,@T73,@T74,@T75,@T76)");
            SqlParameter[] parameters = {
					new SqlParameter("@zap_sb_id", SqlDbType.Int,4),
					new SqlParameter("@zap_sb_no", SqlDbType.VarChar,50),
					new SqlParameter("@zap_sb_name", SqlDbType.VarChar,50),
					new SqlParameter("@T11", SqlDbType.VarChar,50),
					new SqlParameter("@T12", SqlDbType.VarChar,50),
					new SqlParameter("@T13", SqlDbType.VarChar,50),
					new SqlParameter("@T14", SqlDbType.VarChar,50),
					new SqlParameter("@T15", SqlDbType.VarChar,50),
					new SqlParameter("@T16", SqlDbType.VarChar,50),
					new SqlParameter("@T21", SqlDbType.VarChar,50),
					new SqlParameter("@T22", SqlDbType.VarChar,50),
					new SqlParameter("@T23", SqlDbType.VarChar,50),
					new SqlParameter("@T24", SqlDbType.VarChar,50),
					new SqlParameter("@T25", SqlDbType.VarChar,50),
					new SqlParameter("@T26", SqlDbType.VarChar,50),
					new SqlParameter("@T31", SqlDbType.VarChar,50),
					new SqlParameter("@T32", SqlDbType.VarChar,50),
					new SqlParameter("@T33", SqlDbType.VarChar,50),
					new SqlParameter("@T34", SqlDbType.VarChar,50),
					new SqlParameter("@T35", SqlDbType.VarChar,50),
					new SqlParameter("@T36", SqlDbType.VarChar,50),
					new SqlParameter("@T41", SqlDbType.VarChar,50),
					new SqlParameter("@T42", SqlDbType.VarChar,50),
					new SqlParameter("@T43", SqlDbType.VarChar,50),
					new SqlParameter("@T44", SqlDbType.VarChar,50),
					new SqlParameter("@T45", SqlDbType.VarChar,50),
					new SqlParameter("@T46", SqlDbType.VarChar,50),
					new SqlParameter("@T51", SqlDbType.VarChar,50),
					new SqlParameter("@T52", SqlDbType.VarChar,50),
					new SqlParameter("@T53", SqlDbType.VarChar,50),
					new SqlParameter("@T54", SqlDbType.VarChar,50),
					new SqlParameter("@T55", SqlDbType.VarChar,50),
					new SqlParameter("@T56", SqlDbType.VarChar,50),
					new SqlParameter("@T61", SqlDbType.VarChar,50),
					new SqlParameter("@T62", SqlDbType.VarChar,50),
					new SqlParameter("@T63", SqlDbType.VarChar,50),
					new SqlParameter("@T64", SqlDbType.VarChar,50),
					new SqlParameter("@T65", SqlDbType.VarChar,50),
					new SqlParameter("@T66", SqlDbType.VarChar,50),
					new SqlParameter("@T71", SqlDbType.VarChar,50),
					new SqlParameter("@T72", SqlDbType.VarChar,50),
					new SqlParameter("@T73", SqlDbType.VarChar,50),
					new SqlParameter("@T74", SqlDbType.VarChar,50),
					new SqlParameter("@T75", SqlDbType.VarChar,50),
					new SqlParameter("@T76", SqlDbType.VarChar,50)};
            parameters[0].Value = model.zapsbid;
            parameters[1].Value = model.zapsbno??"";
            parameters[2].Value = model.zapsbname;
            parameters[3].Value = model.t11 ?? "";
            parameters[4].Value = model.t12 ?? "";
            parameters[5].Value = model.t13 ?? "";
            parameters[6].Value = model.t14 ?? "";
            parameters[7].Value = model.t15 ?? "";
            parameters[8].Value = model.t16 ?? "";
            parameters[9].Value = model.t21 ?? "";
            parameters[10].Value = model.t22 ?? "";
            parameters[11].Value = model.t23 ?? "";
            parameters[12].Value = model.t24 ?? "";
            parameters[13].Value = model.t25 ?? "";
            parameters[14].Value = model.t26 ?? "";
            parameters[15].Value = model.t31 ?? "";
            parameters[16].Value = model.t32 ?? "";
            parameters[17].Value = model.t33 ?? "";
            parameters[18].Value = model.t34 ?? "";
            parameters[19].Value = model.t35 ?? "";
            parameters[20].Value = model.t36 ?? "";
            parameters[21].Value = model.t41 ?? "";
            parameters[22].Value = model.t42 ?? "";
            parameters[23].Value = model.t43 ?? "";
            parameters[24].Value = model.t44 ?? "";
            parameters[25].Value = model.t45 ?? "";
            parameters[26].Value = model.t46 ?? "";
            parameters[27].Value = model.t51 ?? "";
            parameters[28].Value = model.t52 ?? "";
            parameters[29].Value = model.t53 ?? "";
            parameters[30].Value = model.t54 ?? "";
            parameters[31].Value = model.t55 ?? "";
            parameters[32].Value = model.t56 ?? "";
            parameters[33].Value = model.t61 ?? "";
            parameters[34].Value = model.t62 ?? "";
            parameters[35].Value = model.t63 ?? "";
            parameters[36].Value = model.t64 ?? "";
            parameters[37].Value = model.t65 ?? "";
            parameters[38].Value = model.t66 ?? "";
            parameters[39].Value = model.t71 ?? "";
            parameters[40].Value = model.t72 ?? "";
            parameters[41].Value = model.t73 ?? "";
            parameters[42].Value = model.t74 ?? "";
            parameters[43].Value = model.t75 ?? "";
            parameters[44].Value = model.t76 ?? "";

            DBExecuteUtil.executeSqlWithPar(strSql.ToString(), parameters);
        } 
        public void Update2Idle(int id,string column)
        {
            string s = "UPDATE ZAP2 SET " + column + "='√' WHERE ZAP_SB_ID=" + id;
            DBExecuteUtil.executeSql(s);
        }
        public void Update2Busy(int id, string column)
        {
            string s = "UPDATE ZAP2 SET " + column + "='' WHERE ZAP_SB_ID="+id;
            DBExecuteUtil.executeSql(s);
        } 
        public void Delete(int id)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("delete from zap2 where zap_sb_id="+id);
            DBExecuteUtil.executeSql(sb.ToString());
        }
    }
}
